package com.wy2cloud.core.exception;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * web 控制器 异常全局处理基类 @ControllerAdvice(annotations = {Controller.class})
 * @author wuyy
 *
 */
public abstract class WebBaseGlobalExceptionAdvice extends BaseGlobalExceptionAdvice {
	
	public abstract String getErrorViewName();

	/**
     * 全局处理Exception
     * 错误的情况下返回500
     * @param req
     * @param ex
     * @return
     */
    @ExceptionHandler(value = {Exception.class})
    public ModelAndView handleExceptions(HttpServletRequest req, Exception ex) {
        Logger log= getExceptionClassLogger(ex);
        
        String requestUrl=req.getRequestURI();

        log.error("["+requestUrl+"]发生异常",ex);


        ModelAndView mav = new ModelAndView();
        mav.addObject("url", requestUrl);
        mav.addObject("message", getError());
        mav.addObject("status", "500");
        mav.addObject("error",ex.getMessage() );        
        mav.addObject("exception", ex);
        mav.setViewName(getErrorViewName());
        return mav;
    }


}
